package negModel;

import negModelExcep.eParteNoFunciona;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Escape extends PartePerformance {

	private double porcentajeElim;
		
	public Escape (int vidaUtil, double peso,float aporteVelMax,String detalle,AlgoPesos precio,boolean removible,int performance, double porcentaje){
		this.setMaxVU(vidaUtil);
		this.arreglar();
		this.setPeso(peso);
		this.setAportevmax(aporteVelMax);
		this.setDetalle(detalle);
		this.setPrecio(precio);
		this.setRemovible(removible);
		this.setPerformance(performance);
		
		this.porcentajeElim = porcentaje;
	
		
	}
	
	public Escape (Element xmlElement) {
		this.setMaxVU(Integer.parseInt(xmlElement.getAttribute("maxVU")));
		this.setVidaUtil(Integer.parseInt(xmlElement.getAttribute("vidaUtil")));
		this.setPeso(Double.parseDouble(xmlElement.getAttribute("peso")));
		this.setAportevmax(Float.parseFloat(xmlElement.getAttribute("aportevmax")));
		this.setDetalle(xmlElement.getAttribute("detalle"));
		this.setPrecio(new AlgoPesos(Double.parseDouble(xmlElement.getAttribute("precio"))));
		this.setRemovible(Boolean.parseBoolean(xmlElement.getAttribute("removible")));
		this.setPerformance(Integer.parseInt(xmlElement.getAttribute("performance")));
		
		this.porcentajeElim=Double.parseDouble(xmlElement.getAttribute("porcentajeElim"));
		
	}
	
	public Element toXml(Document doc) {
		Element xmlElement = doc.createElement("parte");
		xmlElement.setAttribute("Clase","escape");
		
		xmlElement.setAttribute("maxVU", ""+ this.getMaxVU());
		xmlElement.setAttribute("vidaUtil", ""+this.getVidaUtil());
		xmlElement.setAttribute("peso", ""+this.getPeso());
		xmlElement.setAttribute("aportevmax", ""+ this.aportevmax());
		xmlElement.setAttribute("detalle", this.getDetalle());
		xmlElement.setAttribute("precio", ""+(this.getPrecio()).getMonto());
		xmlElement.setAttribute("removible", ""+this.esRemovible());
		xmlElement.setAttribute("performance", ""+this.getPerformance());
		
		xmlElement.setAttribute("porcentajeElim", ""+this.porcentajeElim);
		
		return xmlElement;
	}
	
	public double funcionar() throws eParteNoFunciona {
		this.gastar();
		return (porcentajeElim/100);
	}
	
	public double getPorcentajeElim() {
		return porcentajeElim;
	}

	
	
}
